﻿using System;
using System.Data.Entity;
using Dm.Domain.Repository.EntityRepositories;
using Dm.Domain.CrossCutting;

namespace Dm.Domain.Entities.Initializers
{
    public class ContextInitializer : DropCreateDatabaseAlways<BaseContext>
    {

        protected override void Seed(BaseContext context)
        {     
            CreateStatus();
            CreateEmployee();
            CreateKeyAutoGenerators();
      
            CreateStudent();
             base.Seed(context);
        }

        private void CreateStatus()
        {
            var studentStatusRepository = new StatusRepository();

            Status Status1 = new Status();
            Status1.Name = "Active";
            Status1.Description = "Student is currently enrolled";
            Status1.Isactive = true;
            studentStatusRepository.Create(Status1);

            Status Status2 = new Status();
            Status2.Name = "Inactive";
            Status2.Description = "Archived record";
            Status2.Isactive = true;
            studentStatusRepository.Create(Status2);

        }

        private void CreateStudent()
        {
            var studentRepo = new StudentRepository();
            Student student = new Student();
            student.Address = new Address { AddressLine1 = "San Roque, Guagua, Pampanga" };
            student.ContactNumber = "09334518741";
            student.StartDate = new DateTime(2006, 5, 1);
            student.Email = "markjaysonmendoza@hotmail.com";
            student.FirstName = "Mark Jayson";
            student.MiddleName = "Morales";
            student.LastName = "Mendoza";
            student.ControlNumber = "test0001";
            student.StatusId = 1;
            student.YearLevel = 1;
            studentRepo.Create(student);

            Student student2 = new Student();
            student2.Address = new Address { AddressLine1 = "San Roque, Guagua, Pampanga" };
            student2.ContactNumber = "09123456789";
            student2.StartDate = new DateTime(2006, 5, 1);
            student2.Email = "markjaysonmendoza@hotmail.com";
            student2.FirstName = "Nerissa";
            student2.MiddleName = "Gamboa";
            student2.LastName = "Guintu";
            student2.ControlNumber = "test0002";
            student2.StatusId = 1;
            student2.YearLevel = 1;
            studentRepo.Create(student2);

            Student student3 = new Student();
            student3.Address = new Address { AddressLine1 = "San Roque, Guagua, Pampanga" };
            student3.ContactNumber = "09234567890";
            student3.StartDate = new DateTime(2006, 5, 1);
            student3.Email = "wfbermudo@gmail.com";
            student3.FirstName = "William";
            student3.MiddleName = "Felipe";
            student3.LastName = "Bermudo";
            student3.ControlNumber = "test0003";
            student3.StatusId = 1;
            student3.YearLevel = 1;
            studentRepo.Create(student3);

            Student student4 = new Student();
            student4.Address = new Address { AddressLine1 = "Betis Guagua, Pampanga" };
            student4.ContactNumber = "09999999999";
            student4.StartDate = new DateTime(2006, 5, 1);
            student4.Email = "emusngi@gudboy.com";
            student4.FirstName = "Ervin";
            student4.MiddleName = "gudboy";
            student4.LastName = "Musngi";
            student4.ControlNumber = "test0004";
            student4.StatusId = 1;
            student4.YearLevel = 1;
            studentRepo.Create(student4);

            Student student5 = new Student();
            student5.Address = new Address { AddressLine1 = "Marangle" };
            student5.ContactNumber = "0999999345";
            student5.StartDate = new DateTime(2006, 5, 1);
            student5.Email = "boyTangkad@longHair.com";
            student5.FirstName = "Jerome Paul";
            student5.MiddleName = "Emo";
            student5.LastName = "Mercado";
            student5.ControlNumber = "test0005";
            student5.StatusId = 1;
            student5.YearLevel = 1;
            studentRepo.Create(student5);

            Student student6 = new Student();
            student6.Address = new Address { AddressLine1 = "Kabihasnan" };
            student6.ContactNumber = "4563423462";
            student6.StartDate = new DateTime(2006, 5, 1);
            student6.Email = "anotherLongHair@kampuput.com";
            student6.FirstName = "Renaldo";
            student6.MiddleName = "magingSinoKaMan";
            student6.LastName = "Magsino";
            student6.ControlNumber = "test0006";
            student6.StatusId = 1;
            student6.YearLevel = 1;
            studentRepo.Create(student6);

            Student student7 = new Student();
            student7.Address = new Address { AddressLine1 = "Kabundukan" };
            student7.ContactNumber = "324225335";
            student7.StartDate = new DateTime(2007, 5, 1);
            student7.Email = "attorney@kampuput.com";
            student7.FirstName = "Herald";
            student7.MiddleName = "Mapanganib";
            student7.LastName = "Panganiban";
            student7.ControlNumber = "test0007";
            student7.StatusId = 1;
            student7.YearLevel = 1;
            studentRepo.Create(student7);

        }

        private void CreateKeyAutoGenerators()
        {
            KeyAutoGenerator autoGen = new KeyAutoGenerator();
            autoGen.Name = "Student Number";
            autoGen.Definition = "The auto-generated indexer for student numbering";
            autoGen.Indexer = 1;
            autoGen.Prefix = "Pre";
            autoGen.Suffix = "";
            new KeyAutoGeneratorRepository().Create(autoGen);
        }



        private void CreateEmployee()
        {
            Employee employee = new Employee();
            employee.Address = new Address { AddressLine1 = "address line1", AddressLine2 = "address line2" };
            employee.ContactNumber = "123456";
            employee.Email = "mmendoza@blastasia.com";
            employee.ControlNumber = "777";
            employee.FirstName = "Mark Jayson";
            employee.MiddleName = "Morales";
            employee.LastName = "Mendoza";
            employee.User = new User { Password = "password", Username = "username" };
            employee.StatusId = 1;
            new EmployeeRepository().Create(employee);
        }
    }
}
